package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.Wxcache;
import com.ruoyi.system.mapper.WxcacheMapper;
import com.ruoyi.system.service.WxLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class WxLoginServiceImpl  implements WxLoginService {

    @Autowired
    private WxcacheMapper wxcacheMapper;

    @Transactional
    @Override
    public String WxLogin(Wxcache wxcache){
        Wxcache user = wxcacheMapper.selectWxcacheByOpenId(wxcache.getOpenid());
        //判断是否登录过账户
        if(user==null){
            wxcacheMapper.insertWxcache(wxcache);

            return "insert";
        }else if(user.getWxKey()!=wxcache.getWxKey()){
            //更新
            wxcacheMapper.updateWxcache(wxcache);
            return "update";
        }
        //同步
        return "ok";
    }

}
